package com.foton.limiter.construstlimiter.base.config;

import cn.hutool.core.util.ObjectUtil;
import com.foton.limiter.construstlimiter.base.notify.NotifyService;
import com.foton.limiter.construstlimiter.base.notify.NotifyType;
import com.foton.limiter.construstlimiter.base.notify.impl.MailNotifyService;
import com.foton.limiter.construstlimiter.base.notify.impl.SmsNotifyService;
import com.google.common.collect.Maps;
import jdk.nashorn.internal.ir.CallNode;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @Author RenPu
 * @Date 2023/9/4 16:19
 * @Version 1.0
 * @Description: 第三系统通知配置类
 **/

@Service
public class NotifyServiceManager implements InitializingBean {

    @Autowired
   private MailNotifyService mailNotifyService;

    @Autowired
    private SmsNotifyService smsNotifyService;

    Map<Integer,NotifyService> notifymap=Maps.newConcurrentMap();

    @Override
    public void afterPropertiesSet() throws Exception {
        notifymap.put(NotifyType.MAIL.getCode(),mailNotifyService);
        notifymap.putIfAbsent(NotifyType.SMS.getCode(),smsNotifyService);
    }


    public void notifyR(Integer notifyType,String userId,String content){
        NotifyService notifyService = notifymap.get(notifyType);
        if(ObjectUtil.isEmpty(notifyService)){
            throw new RuntimeException(" notify service is not exist ! ! !  please  check your code ");
        }
        notifyService.notifyMessage(userId, content);
    }
}
